package com.ruoyi.common.core.pad;


import com.ruoyi.common.annotation.EffectiveTime;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.RsaUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;


/**
 * ”平板“向”云平台“提交的数据对象基类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "Base class of data objects submitted by tablet to cloud platform.")
public class BasePadToServerDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 接口签名
     */
    @NotBlank(message = "interface signature cannot be empty.")
    @ApiModelProperty(value = "interface signature")
    private String sign;

    /**
     * 平板SN码
     */
    @NotBlank(message = "tablet serial number cannot be empty.")
    @ApiModelProperty(value = "tablet serial number(SN)")
    private String padSn;

    /**
     * 时间戳
     * 平板时间为北京时间，diffTime是指与平板时间与服务器时间相差不能为 60000 ms
     */
    @EffectiveTime(diffTime = 60000, message = "请检查平板时间是否为北京时间")
    @ApiModelProperty(value = "Time on the tablet at data submission.")
    private Long time;

    /**
     * 平板上传方式： 0自动上传   1手动上传    2扫码上传
     */
    private String uploadType = "0";

    /**
     * 用户id信息
     */
    private String userId;
    /**
     * 设备类型
     */
    private String devType;

    /**
     * app类型
     */
    private String appTypes;

    /**
     * 仪器编号
     */
    private String devNum;

    /**
     * 扫码绑定的KEY
     */
    private String bindKey;



    /**
     * 验证接口签名的有效性
     * @return
     */
    public boolean signOk() {
        if (time == null || sign == null) {
            return false;
        } else {
            return RsaUtils.rsaSignVerify(time + "", sign);
        }
    }

    public boolean signOk(String data) {
        return RsaUtils.rsaSignVerify(data, sign);
    }

}
